﻿using System;

namespace RandomPassword
{
    class Program
    {
        static void Main(string[] args)
        {
            int passLenght = 20;
            char[] password = new char[passLenght];

            Random rnd = new Random();

            int n;
            bool isDigit,
                isUpperLetter,
                isLowerLetter,
                isSpecialSymbol;

            while (passLenght > 0)
            {
                n = rnd.Next(35, 123);
                isDigit = (n >= 48 && n <= 57);
                isUpperLetter = (n >= 65 && n <= 90);
                isLowerLetter = (n >= 97 && n <= 122);
                isSpecialSymbol =
                    (n == 35) ||
                    (n == 36) ||
                    (n == 38) ||
                    (n == 98);

                if (
                    isDigit || 
                    isUpperLetter ||
                    isLowerLetter ||
                    isSpecialSymbol
                    )
                {
                    passLenght--;
                    password[passLenght] = (char)n;
                }
            }

            string passwordStr = new string(password);

            Console.WriteLine(passwordStr);

            Console.ReadKey();

        }
    }
}
